#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <project_config.h>

using namespace std;


class jmap {
private:
    string deal_content;
public:
    jmap(string deal_content) {
        this -> deal_content = move(deal_content);
    }

    void load(string config_path) {
        cout << config_path << endl;
        this -> deal_content = get_file_content(config_path);
    }

    std::string mapToString(const std::map<std::string, std::string>& map) {
        std::stringstream ss;
        for (const auto& pair : map) {
            ss << pair.first << "=" << pair.second << "\n";
        }
        std::string result = ss.str();
        return result;
    }

    map<string , string> to_cpp_map() {
        vector<string> lines = split(this -> deal_content , '\n');
        map<string , string> cpp_map;
        for (int i = 0 ; i < lines.size() ;i++) {
            try {
                string at_line = lines[i];
                string key = trim(at_line.substr(0 , at_line.find_first_of("=")));
                string value = trim(at_line.substr(at_line.find_first_of("=")+1 , at_line.size()));
                cpp_map[key] = value;
            }catch(const std::exception& e) {
                continue;
            }
        }
        return cpp_map;
    }
};